In this exercise you must create a pool of connections and get a connection from the pool to implement the stored procedures to complete the following tasks:

Stored procedures are created to carry out routine operations on MySQL databases. They are consistent and make sure that the written SQL queries in the procedures are executed in the same way every time you call the stored procedure.

A stored procedure is created only once, and you store it in the MySQL database. You can call the stored procedures as many times as you need in your Python-based application.

The tasks and the steps that you must follow to complete each one are as follows:

Task 1: Establish a connection

Step one: Import MySQLConnectionPool

Step two: Import Error

Step three: Create a pool named pool_a with two connections. Use a try-except block to handle any possible errors.

Your database configurations are as follows:

dbconfig={"database":"little_lemon_db", "user":"your_username", "password":"your_password"}

Step four: Obtain a connection from pool_a and create a cursor object to communicate with the database.

Task 2: Implement a stored procedure called PeakHours

Step one: Write a SQL CREATE PROCEDURE query for PeakHours

Step two: Run the stored procedure query by invoking execute module on the cursor .

Step three: Invoke callproc to call the stored procedure.

Step four: Fetch the results in a variable called dataset .

Step five: Extract the names of the columns.

Step six: Print the names of the columns.

Step seven: Print the sorted data using for loop.

Task 3: Implement a stored procedure GuestStatus

Step one: Write a SQL CREATE PROCEDURE query for GuestStatus .

Step two: Combine the guest’s first and last name from the booking column using CONCAT .

Step three: Use CASE to implement the following statuses for each guest’s order:

Step four: LEFT JOIN Bookings table with Employees ON EmployeeID

Step five: Run the stored procedure query by invoking execute module on the cursor .

Step six: Invoke callproc to call the stored procedure.

Step seven: Fetch the results in a variable called dataset .

Step eight: Extract the names of the columns.

Step nine: Print the names of the columns.

Step ten: Print the sorted data using for loop.

Step eleven: Close the connection to return it back to the pool.

Conclusion

You have now created a pool of connections and obtained a connection from the pool that implemented the stored procedures. You need to submit this exercise for your peer review project.